package com.nil.codegen.enums;

import lombok.Getter;

import java.util.*;
import java.util.stream.Collectors;

@Getter
public enum DriverTypeEnum {

    MYSQL("MySQL", "MySQL", "com.mysql.cj.jdbc.Driver"),

    DM("DM", "达梦", "dm.jdbc.driver.DmDriver"),

    PGSQL("PostgreSQL", "PgSQL", ""),

    ORACLE("Oracle", "Oracle", "oracle.jdbc.driver.OracleDriver")

    ;


    private final String value;

    private final String label;

    private final String pgName;        // 驱动类名

    DriverTypeEnum(String value, String label, String pgName) {
        this.value = value;
        this.label = label;
        this.pgName = pgName;
    }


    public static DriverTypeEnum getByValue(String value) {
        for (DriverTypeEnum typeEnum : DriverTypeEnum.values()) {
            if (typeEnum.value.equals(value)) {
                return typeEnum;
            }
        }
        return null;
    }

    public static DriverTypeEnum getByLabel(String label) {
        for (DriverTypeEnum DbTypeEnum : DriverTypeEnum.values()) {
            if (DbTypeEnum.label.equals(label)) {
                return DbTypeEnum;
            }
        }
        return null;
    }


    public static Map<String, String> toMap() {
        return Arrays.stream(DriverTypeEnum.values()).collect(Collectors.toMap(DriverTypeEnum::getValue, DriverTypeEnum::getLabel));
    }

    public static List<Map<String, String>> toList() {
        DriverTypeEnum[] values = DriverTypeEnum.values();
        List<Map<String, String>> list = new ArrayList<>();
        for (DriverTypeEnum value : values) {
            Map<String, String> map = new HashMap<>();
            map.put("value", value.getValue());
            map.put("label", value.getLabel());
            list.add(map);
        }
        return list;
    }

}
